package com.zs4sdk.activity.login;

import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewStub;
import android.widget.TextView;

import com.common.library.util.ActivityHelper;
import com.zs4gamesdk.R;
import com.zs4sdk.activity.Zs4GameBaseActivity;
import com.zs4sdk.activity.Zs4GameRetrievePasswordActivityBase;
import com.zs4sdk.common.Extra;

/**
 * Created by Administrator on 2018/4/17.
 */
//com.zs4sdk.activity.login.Zs4GameLoginActivity
public class Zs4GameLoginActivity extends Zs4GameBaseActivity {
    Zs4GameLoginProxyBase mZs4GameLoginProxy;
    private final static byte LOGIN_SELECT = 101;
    private final static byte LOGIN = 102;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        Intent intent = getIntent();
        int style = intent.getIntExtra("loginStyle",LOGIN);
        View mainView = null;
        if(Extra.isComplex()){
            mainView = LayoutInflater.from(this).inflate(R.layout.zs4game_act_login_menu_ft,null);
        }else{
            mainView = LayoutInflater.from(this).inflate(R.layout.zs4game_act_login_menu,null);
        }

        setContentView(mainView);
        Log.e("check"," login style is "+style);
        //zs4gamedimens_width_bannerads
        initViewWidth();
        if(style == LOGIN){
            if(Extra.isComplex()){
                mZs4GameLoginProxy = new Zs4GameLoginProxyFt(this,mainView);
            }else{
                mZs4GameLoginProxy  = new Zs4GameLoginProxy(this,mainView);
            }

        }else{
            ViewStub viewStub = (ViewStub)mainView.findViewById(R.id.stu_login_select);
            viewStub.setVisibility(View.VISIBLE);
            if(Extra.isComplex()){
                mZs4GameLoginProxy  = new Zs4GameSelectLoginProxyFt(this,mainView);
            }else{
                mZs4GameLoginProxy  = new Zs4GameSelectLoginProxy(this,mainView);
            }

        }

    }

    private void initViewWidth(){
        View rootLayout = this.findViewById(R.id.linLoginRoot);
        int windowWidth = this.getResources().getDisplayMetrics().widthPixels;
        int loginWidth = this.getResources().getDimensionPixelSize(R.dimen.zs4gamedimens_width_bannerads);
        if(loginWidth >= windowWidth){
            loginWidth = windowWidth;
        }else if(loginWidth < windowWidth && loginWidth > windowWidth/2){
            // loginWidth = ViewGroup.LayoutParams.WRAP_CONTENT;
            loginWidth = 2*windowWidth/3;
        }else{
            loginWidth = 2*windowWidth/3;
            //  loginWidth = ViewGroup.LayoutParams.WRAP_CONTENT;
        }
        rootLayout.getLayoutParams().width = loginWidth;
    }
    public void onDestroy(){
        super.onDestroy();
        mZs4GameLoginProxy.onDestroy();
    }

    @Override
    public void onBackPressed() {
        //super.onBackPressed();
        mZs4GameLoginProxy.onBackPressed();
    }

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        initViewWidth();
    }
}
